package com.game.majiang.vo;

import java.sql.Types;
import java.util.ArrayList;

import javax.sql.rowset.CachedRowSet;

import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;
import com.game.server.db.entity.HongliTiqu;

public class HongliTiquVo {

	public static void insertInto(int uid, int gold) {
		String sql = "INSERT INTO honglitiqu(uid,gold) VALUES (?,?)";
		Parameter p1 = new Parameter(Types.INTEGER, uid,ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, gold,ParameterType.Input);
		SqlHelperwrite.execute(sql, p1,p2);
	}
	
	public static ArrayList<HongliTiqu> selectUserHongliTiquLog(int uid) {
		ArrayList<HongliTiqu> listHonglilog = new ArrayList<>();
		String sql = "SELECT id,uid,gold,createtime FROM honglitiqu WHERE uid = ? ORDER BY createtime DESC";
		Parameter p1 = new Parameter(Types.INTEGER, uid,ParameterType.Input);
		CachedRowSet resultSet = SqlHelper.getResultSet(sql, p1);
		try {
			while (resultSet.next()) {
				HongliTiqu h = new HongliTiqu();
				h.createtime = resultSet.getString("createtime");
				h.gold = resultSet.getInt("gold");
				h.id = resultSet.getInt("id");
				h.uid = resultSet.getInt("uid");
				listHonglilog.add(h);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return listHonglilog;
	}
	
}
